public class ReversalString {
    //344. 反转字符串
    public static void reversal(char[] chars){
        int left=0;
        int right=chars.length-1;
        while (right>left){
            char temp=chars[left];
            chars[left]=chars[right];
            chars[right]=temp;
            left++;
            right--;
        }
    }

    //557. 反转字符串中的单词 III
    public static String reverseWords(String s){
        String[] temp=s.split(" ");
        StringBuffer buffer=new StringBuffer();
        for (int i = 0; i <temp.length ; i++) {
            String os=temp[i];
            char[] chars=os.toCharArray();
            reversal(chars);
            buffer.append(chars).append(" ");
        }

        return buffer.toString().trim();
    }

    public static void main(String[] args) {
        String s="Let's take LeetCode contest";
        System.out.println(reverseWords(s));
    }
}
